<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box{
        width: 233px;
        height: 500px;
    }
</style>
<body>
    <div class="box">
        昵称：<input type="text" id="n"><br><br>
        <textarea name="" id="" cols="30" rows="10"></textarea><br>
        <input type="checkbox" id="cheackbox">匿名
        <button type="button" style="float: right;">发表</button>
    </div>
</body>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
    const $name = $("#n");
    const $text = $("textarea");
    const $checkbox = $("#cheackbox");
    $("button").click(function () {
        if ($name.val() === "") {
            alert("名字不能为空");
            return;
        } else if ($text.val() === "") {
            alert("文本不能为空");
            return;
        }
        const date = new Date();
        const a = date.getHours()<12?"上午":"下午";
        const time = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
        if($checkbox.prop("checked")){
            const $div = $("<div>路人甲 "+a+time+"<br>"+$text.val()+"</div>");
            $(".box").append($div);
        } else {
            const $div = $("<div>昵称："+$name.val()+" "+a+time+"<br>"+$text.val()+"</div>");
            $(".box").append($div);
        }
    })
</script>
</html>